package com.example.cloud.controller.basic.config;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.example.cloud.controller.common.BaseController;
import com.example.cloud.model.dto.QueryModel;
import com.example.cloud.model.dto.Result;
import com.example.cloud.model.statistics.CreditItems;
import com.example.cloud.service.basic.config.CreditItemsService;
import com.example.cloud.utils.ResultUtil;

@RestController
@RequestMapping("/credititems")
public class CreditItemsController extends BaseController {
      @Autowired
	    private CreditItemsService creditItemsService;

	    @PostMapping("/search")
	    public Result search(@RequestBody QueryModel model) {
	        return this.singleQuery(model, CreditItems.class);
	    }

	    @GetMapping("/findAll")
	    public Result findAll(){
	        return ResultUtil.success(creditItemsService.findAllFromCache());
	    }

	    @PostMapping("/saveOrUpdate")
	    public void saveOrUpdate(@RequestBody CreditItems record){
	    	creditItemsService.doSave(record);
	    }

	    @PostMapping("/delete")
	    public void delete(@RequestBody List<Long> ids){
	    	creditItemsService.doDelete(ids);
	    }
	    
	    @GetMapping("/findCreditItems/{creditType}")
	    public Result findCreditItems(@PathVariable int creditType) {
	      return ResultUtil.success(creditItemsService.findCreditItems(creditType));
	    }
	    
}
